<template>
  <div class="hello">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.userName"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.passWord"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import axios from 'axios'
  export default {
    data() {
      return {
        form: {
          userName: "",
          passWord: "",
        }
      }
    },
    methods: {
      onSubmit() {
        console.log(this.form);
        axios.post("http://47.110.234.216:7001/login", {
          username: this.form.userName,
          password: this.form.passWord,
        }).then(res => {
          console.log(res.data.status)
          if (res.data.status) {
            this.$router.push("/page");
          }
          else {
            this.$message.error('用户名或密码错误');
          }
        });

      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  el-input {
    width: 600px;
  }

  h1, h2 {
    font-weight: normal;
  }

  ul {
    list-style-type: none;
    padding: 0;
  }

  li {
    display: inline-block;
    margin: 0 10px;
  }

  a {
    color: #42b983;
  }
</style>
